package org.example;


import cn.hserver.core.ioc.annotation.Bean;
import cn.hserver.core.server.util.protocol.ProtocolUtil;
import cn.hserver.plugin.cloud.ServerInstance;
import cn.hserver.plugin.gateway.bean.Http4Data;
import cn.hserver.plugin.gateway.business.BusinessHttp4;
import cn.hserver.plugin.gateway.business.BusinessHttp7;
import cn.hserver.plugin.rpc.core.RpcDisHandler;
import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.util.Attribute;
import io.netty.util.AttributeKey;

import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.util.List;
import java.util.concurrent.atomic.LongAdder;

@Bean
public class Http7 extends BusinessHttp7 {
    @Override
    public String upIgnoreUrls() {
        return "/upload*";
    }

    @Override
    public String downIgnoreUrls() {
        return "/down*";
    }

    @Override
    public SocketAddress getProxyHost(ChannelHandlerContext ctx, Object fullHttpRequest, SocketAddress sourceSocketAddress) {
        //轮训策略选择一个
        final var chose = RpcDisHandler.getRpcDisHandler().chose("WEB", "web");
        return new InetSocketAddress(chose.getIp(), chose.getPort());
    }


    @Override
    public Object in(ChannelHandlerContext ctx, Object obj) {
        System.out.println("入消息类型："+obj.getClass());
        return obj;
    }

    @Override
    public Object out(Channel channel, Object obj) {
        System.out.println("出消息类型："+obj.getClass());
        return super.out(channel, obj);
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
        cause.printStackTrace();
    }
}
